package com.simple.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {
	
	/**
	 * 时间戳转时间字符串
	 * @param timestamp
	 * @return yyyy-MM-dd HH:mm:ss
	 */
	public static String Long2String(Long timestamp){
		SimpleDateFormat sf =  new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String time = null;
		if(null !=timestamp)
			time = sf.format(timestamp);
		return time;
		
	}
	
	/**
	 * 时间戳转时间字符串
	 * @param timestamp
	 * @return yyyy-MM-dd
	 */
	public static String Long2String2(Long timestamp){
		SimpleDateFormat sf =  new SimpleDateFormat("yyyy-MM-dd");
		String time = null;
		if(null !=timestamp)
			time = sf.format(timestamp);
		return time;
		
	}
	
	/**
	 * 时间戳转时间字符串
	 * @param timestamp
	 * @return HH:mm:ss
	 */
	public static String Long2String3(Long timestamp){
		SimpleDateFormat sf =  new SimpleDateFormat("HH:mm:ss");
		String time = null;
		if(null !=timestamp)
			time = sf.format(timestamp);
		return time;
		
	}
	
	
	
	public static Date getEndTime(Date date) {     
		Calendar dateEnd = Calendar.getInstance();     
		dateEnd.setTime(date);    
		dateEnd.set(Calendar.HOUR_OF_DAY, 23);    
		dateEnd.set(Calendar.MINUTE, 59);     
		dateEnd.set(Calendar.SECOND, 59);     
		return dateEnd.getTime(); 
	}
	
	public static Long getEndTimeLongYYMMDD(String dateStr) { 
		
		Calendar dateEnd = Calendar.getInstance();     
		dateEnd.setTime(strToDateLongYYMMDD(dateStr));    
		dateEnd.set(Calendar.HOUR_OF_DAY, 23);    
		dateEnd.set(Calendar.MINUTE, 59);     
		dateEnd.set(Calendar.SECOND, 59);     
		return dateEnd.getTime().getTime(); 
	}

	public static Long getStartTimeLongYYMMDD(String dateStr) {
		Calendar dateEnd = Calendar.getInstance();
		dateEnd.setTime(strToDateLongYYMMDD(dateStr));
		dateEnd.set(Calendar.HOUR_OF_DAY, 0);
		dateEnd.set(Calendar.MINUTE, 0);
		dateEnd.set(Calendar.SECOND, 0);
		return dateEnd.getTime().getTime();
	}
	
	public static Date getStartTime(Date date) {     
		Calendar dateEnd = Calendar.getInstance();     
		dateEnd.setTime(date);    
		dateEnd.set(Calendar.HOUR_OF_DAY, 0);    
		dateEnd.set(Calendar.MINUTE, 0);     
		dateEnd.set(Calendar.SECOND, 0);     
		return dateEnd.getTime(); 
	}
	
	 public static Date strToDateLong(String strDate) {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date strtodate = null;
		try {
			strtodate = formatter.parse(strDate);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return strtodate;
	}
	
	 public static Date strToDateLongYYMMDD(String strDate) {
			SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
			Date strtodate = null;
			try {
				strtodate = formatter.parse(strDate);
			} catch (ParseException e) {
				e.printStackTrace();
			}
			return strtodate;
		}
	

}
